//
//  RVFavoriteController.swift
//  AirTravel
//
//  Created by apple on 2021/11/11.
//

import UIKit

class RVFavoriteController: CommonVC {

    @IBOutlet weak var collectionView: UICollectionView!

    @IBOutlet weak var viewtop: NSLayoutConstraint!
    override func viewDidLoad() {
        super.viewDidLoad()
        head.title.text = "我的收藏"
        confCollectionView()
    }

    
    func confCollectionView(){
        viewtop.constant = TopSpaceHeight
        collectionView.backgroundColor=UIColor.init(hexString: "f7f7f7")
        let layout = CollectionViewWaterfallLayout()
        layout.sectionInset = UIEdgeInsets(top: 15, left: 15, bottom: 0, right: 15)
        layout.headerHeight = 0
        layout.footerHeight = 0
        layout.minimumColumnSpacing = 15
        layout.minimumInteritemSpacing = 15
        collectionView.collectionViewLayout = layout
        
        collectionView.register(UINib(nibName: "RVFavoriteCell", bundle: nil), forCellWithReuseIdentifier: "favorite_cell")
    }

    
}

extension RVFavoriteController: UICollectionViewDataSource {
    func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
        return 1
    }
    
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return 30
    }
    
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "favorite_cell", for: indexPath) as! RVFavoriteCell
        return cell
    }
    
   
}


// MARK: - CollectionViewWaterfallLayoutDelegate
extension RVFavoriteController: CollectionViewWaterfallLayoutDelegate {
    func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
        let isShowTag = arc4random()%2
        let width = (ScreenWidth - 45)/2
        
        if isShowTag == 1 {
            return CGSize(width: width, height: 319)
        }else{
            return CGSize(width: width, height: 299)
        }
    }
}

